package com.x.Part3_variable;

public class Variable {
    public static void main(String[] args) {
        //字符串
        System.out.printf("Hello and welcome!");
        //整数
        System.out.println(666);
        //小数
        System.out.println(99.5);
        //字符
        System.out.println('a');
        System.out.println('\n');//换行
        System.out.println('\t');//缩进
        System.out.println('0');
        System.out.println(' ');
        //System.out.println('');错误
        //System.out.println('aa');错误

        int a = 24;
        double b = 99.5;
        {
            int c = 5;
            System.out.println(c);
        }
        //括号内的变量无法访问，c的范围在7-10行
        //System.out.println(c);

        //对于局部变量，可以使用关键字var初始化变量，而无需指定类型
        var greeting = "Hello!";
        System.out.println(greeting+"\n"); //加一个换行符

        //枚举类型了解
        enum Size {small, medium, large, extra_large};  //声明Size
        Size hanXu = Size.extra_large;                  //初始化hanXu

        //强制类型转换
        double x = 9.97;
        int ix = (int) x;
        System.out.println(ix);//输出9，截断小数部分

        int nx = (int) Math.round(x);
        System.out.println(nx);//输出10，舍入方法round()，round()返回值是long类型，仍需类型转换


    }
}
